#include "ClockSuscriptor.h"

/* =============================================================================
 * Declaracion Atributos privados
 * =============================================================================
 */

struct ClockSuscriptor{
  tDato suscriptor;
  tFcnClockNotificar notificar;  
};

typedef struct ClockSuscriptor* _tClockSuscriptor;

/*==============================================================================
 * Definicion de metodos publicos
 *==============================================================================
 */

void clockSuscriptorCrear (tClockSuscriptor* pClockSuscriptor, tDato pSuscriptor, tFcnClockNotificar pClockNotificar){
  
  _tClockSuscriptor clockSuscriptor = NULL;
  
  if (pSuscriptor && pClockNotificar)
  {
    clockSuscriptor = (_tClockSuscriptor) malloc (sizeof (struct ClockSuscriptor));
    
    if (clockSuscriptor)
    {
      clockSuscriptor->suscriptor = pSuscriptor;
      clockSuscriptor->notificar = pClockNotificar;
    }
  }
  *pClockSuscriptor = clockSuscriptor;
}

//------------------------------------------------------------------------------

int clockSuscriptorDestruir(tClockSuscriptor pClockSuscriptor){

    // Importante.  El ClockSuscriptor no tiene la potestad de destruir el dato.
    
    int val = DATO_ERROR;
  
    if (pClockSuscriptor)
    {
        free ((_tClockSuscriptor) pClockSuscriptor);
        val = DATO_OK;
    }
    return val;
}

//------------------------------------------------------------------------------

tDato clockSuscriptorGetSuscriptor(tClockSuscriptor pClockSuscriptor){
  
  tDato val = NULL;
  
  if (pClockSuscriptor)
    val = ((_tClockSuscriptor)pClockSuscriptor)->suscriptor;
    
  return val;
}

//------------------------------------------------------------------------------

tFcnClockNotificar clockSuscriptorGetFcnClockNotificar (tClockSuscriptor pClockSuscriptor){

  tFcnClockNotificar val = NULL;
  
  if (pClockSuscriptor)
    val = ((_tClockSuscriptor)pClockSuscriptor)->notificar;
    
  return val;
}
